package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/page")
    public Result<PageResult> pageFind(SetmealPageQueryDTO dto) {
        log.info("套餐分页查询接收的参数:{}", dto);
        PageResult pageResult = setmealService.pageFind(dto);
        return Result.success(pageResult);
    }

    @PostMapping()
    public Result<String> save(@RequestBody SetmealDTO dto) throws Exception {
        setmealService.save(dto);
        return Result.success();
    }

    @DeleteMapping
    public Result<String> delete(@RequestParam List<Integer> ids) throws Exception {
        setmealService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{setmealId}")
    public Result<SetmealVO> selectById(@PathVariable("setmealId") Long id) {
        SetmealVO vo = setmealService.selectById(id);
        return Result.success(vo);
    }
    @PutMapping
    public Result<String> put(@RequestBody SetmealDTO dto){
        setmealService.put(dto);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result<String> putStatus(@PathVariable Integer status,Long id) throws Exception {
        log.info("修改起售状态接收的参数:{},{}", status,id);
        setmealService.putStatus(status,id);
        return Result.success();
    }
}
